 export const  getVideoThumbnail = (file: File): Promise<{ base64edData: string, originalWidth: number, originalHeight: number, duration: number }>  => {
    return new Promise((resolve, reject) => {
        const video = document.createElement('video');
        const fileReader = new FileReader();
        // 读取文件为URL
        fileReader.onload = () => {
            video.src = fileReader.result as string;

            // 当元数据加载完成后
            video.onloadedmetadata = () => {
                const duration = video.duration;

                // 获取视频第一帧
                video.onseeked = () => {
                    const canvas = document.createElement('canvas');
                    const ctx = canvas.getContext('2d');

                    if (!ctx) {
                        reject(new Error('Failed to get canvas context'));
                        return;
                    }

                    const originalWidth = video.videoWidth;
                    const originalHeight = video.videoHeight;
                    const targetSize = 120;
                    const scale = Math.min(targetSize / originalWidth, targetSize / originalHeight);

                    canvas.width = originalWidth * scale;
                    canvas.height = originalHeight * scale;

                    ctx.drawImage(video, 0, 0, canvas.width, canvas.height);

                    // 将canvas内容转化为base64
                    const base64edData = canvas.toDataURL('image/jpeg', 0.45).replace(/^data:image\/(png|jpg);base64,/, "");

                    resolve({ base64edData, originalWidth, originalHeight, duration });
                };

                // 求视频的第一帧
                video.currentTime = 0;
            };
        };

        // 读取文件
        fileReader.readAsDataURL(file);
    });
}